package com.blueheart.music.service.impl;

import com.blueheart.music.exception.BaseException;
import com.blueheart.music.exception.BaseExceptionEnum;
import com.blueheart.music.mapper.SongListMapper;
import com.blueheart.music.model.pojo.SongList;
import com.blueheart.music.service.SongListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SongListServiceImpl implements SongListService {
    @Autowired
    private SongListMapper songListMapper;
    /**
     * 增
     *
     * @param songList
     * @return
     */
    @Override
    public Boolean addSongList(SongList songList) {
        return songListMapper.insertSelective(songList)>0;
    }

    /**
     * 删
     *
     * @param id
     * @return
     */
    @Override
    public Boolean removeSonglist(Integer id) {
        return songListMapper.deleteByPrimaryKey(id)>0;
    }

    /**
     * 改
     *
     * @param songList
     * @return
     */
    @Override
    public Boolean reviseSongList(SongList songList) {
        return songListMapper.updateByPrimaryKeySelective(songList)>0;
    }

    /**
     * 查询全部
     *
     * @return
     */
    @Override
    public List<SongList> findAll() {
        return songListMapper.selectAll();
    }

    /**
     * 模糊查询歌单
     *
     * @return
     */
    @Override
    public List<SongList> findFromName(String title) {
        return songListMapper.selectFromList(title);
    }

    /**
     * 精准查询歌单
     *
     * @param title
     * @return
     */
    @Override
    public SongList findByName(String title) {
        return songListMapper.selectByName(title);
    }

    /**
     * id查询歌单
     *
     * @param id
     * @return
     */
    @Override
    public SongList findById(Integer id) {
        return songListMapper.selectByPrimaryKey(id);
    }

    /**
     * 重名判断
     *
     * @param title
     * @return
     */
    @Override
    public SongList checkName(String title) {
        SongList songList = songListMapper.selectByName(title);
        if (songList!=null){
            throw new BaseException(BaseExceptionEnum.SONGLIST_EXIST);
        }
        return songList;
    }

    /**
     * 根据风格查询歌单
     *
     * @param style
     * @return
     */
    @Override
    public List<SongList> findByStyle(String style) {
        return songListMapper.selectByStyle(style);
    }
}
